<?php
define('ROOTDIR', substr(dirname(__FILE__), 0, -7));
require 'install.func.php';
header("Content-type: text/html; charset=utf-8");

if (PHP_VERSION >= "5.1.0")
{
	date_default_timezone_set( 'Asia/Shanghai' );
}
$step = isset($_GET['step']) ? (int)$_GET['step'] : 1;
if(file_exists(ROOTDIR . 'conf/install.lock'))
{
	$success1 = '<h1 class="green">图书管理系统 已经安装！</h1>';
	$success2 = '<ul class="info">
<li class="red">应用程序已经安装过！请勿重新安装！</li>
<li>若要重新安装，请删除 conf/install.lock ，然后重新执行此安装程序！</li>
</ul>';
	$notice = 1;
	$step   = 3;
}
if($step == 3 && !isset($notice) && !file_exists(ROOTDIR . 'conf/install.lock'))
{
	$dbconn = $install_error = '';
	$setting['dbhost']    = trim($_POST['dbhost']);
	$setting['dbport']    = trim($_POST['dbport']);
	$setting['dbuser']    = trim($_POST['dbuser']);
	$setting['dbpass']    = $_POST['dbpass'];
	$setting['dbname']    = trim($_POST['dbname']);
	$setting['dbadapter'] = trim($_POST['dbadapter']);
	$setting['dbpre']     = trim($_POST['dbpre']);
	$setting['url']       = trim($_POST['url']);
	$setting['username']  = trim($_POST['username']);
	$setting['userpass']  = trim($_POST['userpass']);
	if(creat_mysql($setting) && create_table($setting) && create_conf($setting))
	{
		$success1 = '<h1 class="green">恭喜您！ 图书管理系统 已成功安装！</h1>';
		$success2 ='<ul class="info">
    <li class="red">请记得删除 install/index.php 文件！</li>
    <li><a href="../admin">后台管理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="../">系统主页</a></li>
    </ul>
';
	}
}
@include 'step/step_' . $step . '.php';
?>